package com.zou.controller;

import com.zou.pojo.Books;
import com.zou.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {
    @Resource(name = "BookServiceImpl")
    private BookService bookService;

    @RequestMapping("allbook")
    public String list(Model model){
        List<Books> books=bookService.queryallbook();
        model.addAttribute("books",books);
        return "allbook";
    }
    @RequestMapping("toaddbook")
    public String addBook1(){
        return "addbook";
    }
    @RequestMapping("addbook")
    public String addBook2(Books book){
        bookService.addbook(book);
        return "redirect:/book/allbook";
    }
    @RequestMapping("todeletebook")
    public String deletebook1(){
        return "deletebook";
    }
    @RequestMapping("deletebook")
    public String deletebook2(int bookID){
        bookService.deletebook(bookID);
        return "redirect:/book/allbook";
    }


}
